<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片跟随鼠标移动</title>
    <style>
        img {
            width: 80px;
            border-radius: 50%;
        }
    </style>
</head>

<body>
    <img src="./宠物.jpg" alt="">
    <script>
        let img = document.getElementsByTagName("img")[0];
        window.addEventListener("click", function() {
            img.style.margin = `${event.clientY-40}px 0px 0px ${event.clientX-40}px`
        }, false);
    </script>
</body>

</html>